package org.zjt.platform.druiddemo;

import org.zjt.platform.druiddemo.service.IUserManagerService;
import org.zjt.platform.druiddemo.service.impl.UserManagerServiceImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapperResultSetExtractor;

@SpringBootApplication
public class DruidDemoApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(DruidDemoApplication.class, args);

		IUserManagerService userManagerService = configurableApplicationContext.getBean(IUserManagerService.class);

		userManagerService.findUser();

		JdbcTemplate jdbcTemplate = configurableApplicationContext.getBean(JdbcTemplate.class);
		jdbcTemplate.query("SELECT t.* FROM test.t_users t LIMIT 50",new RowMapperResultSetExtractor((resultSet, i) -> {
            String string = resultSet.getString(2);
            System.err.println(string);
            return null;
        }));
	}

	@Bean
	public IUserManagerService iUserManagerService(){
		UserManagerServiceImpl userManagerService = new UserManagerServiceImpl();
		userManagerService.setName("zhangsan");
		return userManagerService;
	}
}
